//
//  DDBossChoosePositionViewController.m
//  DingDongZP
//
//  Created by Jyh on 16/5/15.
//  Copyright © 2016年 iyhjiang.com. All rights reserved.
//

#import "DDBossChoosePositionViewController.h"
#import "DDChatMessageViewController.h"

#import "DDCompanyInfo.h"

#import "DDChoosePositionCell.h"

@interface DDBossChoosePositionViewController ()

// 职位模型
@property (nonatomic, strong) DDCompanyInfo *companyInfo;

// 职位数组
@property (nonatomic ,strong) NSArray *jobsDetailArr;

@end


@implementation DDBossChoosePositionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"选择职位";
    
    [self requestMyPublishedJobsInfo];
    self.tableView.backgroundColor = [UIColor colorWithRed:0.937 green:0.941 blue:0.945 alpha:1.000];
    self.tableView.rowHeight = 100;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    
}

- (void)requestMyPublishedJobsInfo {
    
    WEAKSELF
    [[LDBossInfoNet sharedInstance] queryCompanyInfo:^(NSDictionary * _Nonnull dict) {
        
        DDCompanyInfo *companyinfo = [DDCompanyInfo yy_modelWithDictionary:dict];
        weakSelf.companyInfo = companyinfo;
        weakSelf.jobsDetailArr = companyinfo.jobs;
        
        [weakSelf.tableView reloadData];
        
    } failure:^(id  _Nonnull error) {
        
    }];
    
}

#pragma mark - UITableView Delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return _jobsDetailArr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    DDChoosePositionCell *cell = [DDChoosePositionCell loadTableView:tableView];
    cell.detail = self.jobsDetailArr[indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 70;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 70)];
    headerView.userInteractionEnabled = YES;
    UILabel *headTitleLable = [[UILabel alloc]init];
    headTitleLable.text = @"您希望与牛人沟通如下哪个职位";
    headTitleLable.textAlignment = 1;
    headTitleLable.textColor = COLOR_FONT_LIGHT_GRAY;
    headTitleLable.font = [UIFont systemFontOfSize:16];
    [headerView addSubview:headTitleLable];
    [headTitleLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(headerView);
    }];
    
    return headerView;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DDChatMessageViewController *ddChatMessageViewController = [[DDChatMessageViewController alloc]initWithConversationType:ConversationType_PRIVATE targetId:self.targetID];
    ddChatMessageViewController.title = self.titleName;
    ddChatMessageViewController.jobid = self.companyInfo.jobs[indexPath.row].jobid;
    
    [self.navigationController pushViewController:ddChatMessageViewController animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
